#include "UserInterface.h"

int displayMenu()
{
	int selection;
	cout << endl;
	cout << "-------------------------------" << endl;
	cout << "1) Hire a new employee" << endl;
	cout << "2) Fire an employee" << endl;
	cout << "3) Promote an employee" << endl;
	cout << "4) List all employees" << endl;
	cout << "5) List all current employees" << endl;
	cout << "6) List all previous employees" << endl;
	cout << "0) Quit" << endl;
	cout << endl;
	cout << "--->";
	cin >> selection;
	return selection;
}

void doHire(Database& inDB)
{
	string firstName;
	string lastName;
	cout << "First name?";
	cin >> firstName;
	cout << "Last name?";
	cin >> lastName;

	try {
		inDB.addEmployee(firstName, lastName);
	} catch (const std::exception&) {
		cerr << "Unable to add new employee!" << endl;
	}
}

void doFire(Database& inDB)
{
	int employeeNumber;
	cout << "Employee number?";
	cin >> employeeNumber;

	try {
		Employee& emp = inDB.getEmployee(employeeNumber);
		emp.fire();
		cout << "Employee" << employeeNumber << "terminated." << endl;
	} catch (const std::exception&) {
		cerr << "Unable to terminated employee!" << endl;
	}
}

void doPromote(Database& inDB)
{
	int employeeNumber;
	int raiseAmout;
	cout << "Employee number?";
	cin >> employeeNumber;
	cout << "How much of a raise?";
	cin >> raiseAmout;
	
	try {
		Employee& emp = inDB.getEmployee(employeeNumber);
		emp.promote(raiseAmout);
	} catch (const std::exception&) {
		cerr << "Unable to promote employee!" << endl;
	}
}

void doDemote(Database& inDB)
{
	int employeeNumber;
	int raiseAmout;
	cout << "Employee number?";
	cin >> employeeNumber;
	cout << "How much of a raise?";
	cin >> raiseAmout;
	
	try {
		Employee& emp = inDB.getEmployee(employeeNumber);
		emp.demote(raiseAmout);
	} catch (const std::exception&) {
		cerr << "Unable to demote employee!" << endl;
	}
}
